<!DOCTYPE html>
<html>
<head>
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>小程序速记[基础] | Anson&#39;s Blog | 种一棵树最好的时间在十年前，其次是现在。</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="微信小程序">
    <meta name="description" content="小程序基础JSON project.config.json: 项目配置文件 app.json: 全局配置文件 page.json: 项目配置文件 app.json 配置相对应页面的路由（全局配置），window窗口配置：，各页面配置：，tab标签配置 每个页面对应的page.json 也可以配置window 信息，如与app.json相同则覆盖app.json配置  WXML 模板语法 在wxml">
<meta name="keywords" content="微信小程序">
<meta property="og:type" content="article">
<meta property="og:title" content="小程序速记[基础]">
<meta property="og:url" content="http://yoursite.com/2019/08/16/小程序速查/index.html">
<meta property="og:site_name" content="Anson&#39;s Blog">
<meta property="og:description" content="小程序基础JSON project.config.json: 项目配置文件 app.json: 全局配置文件 page.json: 项目配置文件 app.json 配置相对应页面的路由（全局配置），window窗口配置：，各页面配置：，tab标签配置 每个页面对应的page.json 也可以配置window 信息，如与app.json相同则覆盖app.json配置  WXML 模板语法 在wxml">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-08-27T07:49:13.344Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="小程序速记[基础]">
<meta name="twitter:description" content="小程序基础JSON project.config.json: 项目配置文件 app.json: 全局配置文件 page.json: 项目配置文件 app.json 配置相对应页面的路由（全局配置），window窗口配置：，各页面配置：，tab标签配置 每个页面对应的page.json 也可以配置window 信息，如与app.json相同则覆盖app.json配置  WXML 模板语法 在wxml">
    
        <link rel="alternate" type="application/atom+xml" title="Anson&#39;s Blog" href="/atom.xml">
    
    <link rel="shortcut icon" href="/img/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu"  >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="https://yscoder.github.io/img/face.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">张宁乐</h5>
          <a href="mailto:zhangningle2017@gmail.com" title="zhangningle2017@gmail.com" class="mail">zhangningle2017@gmail.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                归档
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/about"  >
                <i class="icon icon-lg icon-user"></i>
                关于
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/ansonznl" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">小程序速记[基础]</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">小程序速记[基础]</h1>
        <h5 class="subtitle">
            
                <time datetime="2019-08-16T06:49:03.000Z" itemprop="datePublished" class="page-time">
  2019-08-16
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#小程序基础"><span class="post-toc-number">1.</span> <span class="post-toc-text">小程序基础</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#JSON"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">JSON</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#WXML"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">WXML</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#WXSS"><span class="post-toc-number">1.3.</span> <span class="post-toc-text">WXSS</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#JS"><span class="post-toc-number">1.4.</span> <span class="post-toc-text">JS</span></a></li></ol></li><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#小程序云开发（ServerLess）"><span class="post-toc-number">2.</span> <span class="post-toc-text">小程序云开发（ServerLess）</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#云数据库"><span class="post-toc-number">2.1.</span> <span class="post-toc-text">云数据库</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#云函数"><span class="post-toc-number">2.2.</span> <span class="post-toc-text">云函数</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#云储存"><span class="post-toc-number">2.3.</span> <span class="post-toc-text">云储存</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Bug"><span class="post-toc-number">2.4.</span> <span class="post-toc-text">Bug</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#参考"><span class="post-toc-number">2.5.</span> <span class="post-toc-text">参考</span></a></li></ol></li></ol>
        </nav>
    </aside>


<article id="post-小程序速查"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">小程序速记[基础]</h1>
        <div class="post-meta">
            <time class="post-time" title="2019-08-16 14:49:03" datetime="2019-08-16T06:49:03.000Z"  itemprop="datePublished">
2019-08-16
<!--2019-08-27 15:49:13-->
</time>

            


            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h1 id="小程序基础"><a href="#小程序基础" class="headerlink" title="小程序基础"></a>小程序基础</h1><h2 id="JSON"><a href="#JSON" class="headerlink" title="JSON"></a>JSON</h2><ul>
<li>project.config.json: 项目配置文件 app.json: 全局配置文件 page.json: 项目配置文件</li>
<li>app.json 配置相对应页面的路由（全局配置），window窗口配置：，各页面配置：，tab标签配置</li>
<li>每个页面对应的page.json 也可以配置window 信息，如与app.json相同则覆盖app.json配置</li>
</ul>
<h2 id="WXML"><a href="#WXML" class="headerlink" title="WXML"></a>WXML</h2><ul>
<li>模板语法 在wxml 中使用双大括号，在双引号中使用有效。</li>
<li><p>for 循环<br>其中有两个值，item 代表每一项，index 代表当前项的索引，并且小程序推荐的使用wx:for 的元素上使用<br>当页面发生改变重新渲染时，框架会效验key ，并重新排序，而非重新渲染，极大的提升了性能。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wx:for = &quot;&#123;&#123; value &#125;&#125;&quot; </span><br><span class="line">wx:key =&quot; &#123;&#123; index &#125;&#125;&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>block 标签 用于一个渲染一个包含多节点的结构块，可以在</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;block wx:for=&quot;&#123;&#123;arr or obj&#125;&#125;&quot;&gt;</span><br><span class="line"> &lt;view&gt;&#123;&#123;item&#125;&#125;&lt;/view&gt;</span><br><span class="line">&lt;/block&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>里的内容会渲染，block不会被循环，</p>
<ul>
<li>wx: if &amp; wx:elif &amp; wx:else 表示显示隐藏元素，true渲染元素，false不渲染元素</li>
<li>wx: hidden 接受一个布尔值，true隐藏，false显示，使用的是display 的black &amp; none 控制</li>
<li>data-*元素只能设置小写字母，就算设置成大写最后取值也是小写</li>
</ul>
<h2 id="WXSS"><a href="#WXSS" class="headerlink" title="WXSS"></a>WXSS</h2><ul>
<li>app.wxss:可写全局样式</li>
<li>rpx: 小程序中的响应式单位，在iPhone6下，1px = 2rpx ，所以设计稿可以使用iPhone6作为标准设计</li>
<li>import : 使用@import ‘../common.wxss’ 可以导入其他样式表</li>
</ul>
<h2 id="JS"><a href="#JS" class="headerlink" title="JS"></a>JS</h2><ul>
<li>setData: 当改变data的值时，需要用到setData，<a href="https://blog.csdn.net/qq_42817227/article/details/84834210" target="_blank" rel="noopener">参考链接</a></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">this.setData(&#123;</span><br><span class="line">    count: this.data.count+1,//改变string &amp; numbert</span><br><span class="line">    &apos;arr[0].name&apos;: &apos;张宁乐&apos;,//改变数组</span><br><span class="line">    &apos;obj.name&apos;: &apos;我已经改变&apos;//改变对象</span><br><span class="line">  &#125;)</span><br></pre></td></tr></table></figure>
<ul>
<li><code>bind</code>绑定事件会冒泡，<code>catch</code> 绑定的事件不会冒泡</li>
<li>当组件在元素上触发时，会向绑定的函数传递一个“事件对象”<code>event</code>，通过它可以获得该组件的相关的信息（比如自定义数据等）</li>
<li>使用<code>input</code>时需要绑定<code>bindinput</code>事件，向M层的同步数据。</li>
</ul>
<h1 id="小程序云开发（ServerLess）"><a href="#小程序云开发（ServerLess）" class="headerlink" title="小程序云开发（ServerLess）"></a>小程序云开发（ServerLess）</h1><p>云开发  三大基础能力支持</p>
<ul>
<li>云函数：获取appid、获取openid 生成分享图、调用腾讯云sdk、数据库的操作</li>
<li>云数据库：对数据的增删改查</li>
<li>云存储： 管理文件 上传文件 下载文件 分享文件  可视化操作</li>
</ul>
<h2 id="云数据库"><a href="#云数据库" class="headerlink" title="云数据库"></a>云数据库</h2><blockquote>
<p>NoSql 数据库，类似mongoDB，存储json格式数据<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">const db = wx.cloud.database();//获取数据库引用</span><br><span class="line">const todos = db.collection(&apos;todos&apos;);//获取集合引用</span><br></pre></td></tr></table></figure></p>
</blockquote>
<p><strong>标识，最好是_id，{}为全部， 元素，操作的元素key:value，默认{} 为全部</strong></p>
<ul>
<li>增<code>todos.add({data:{...}}).then(..).catch(..)</code></li>
<li>删<code>todos.doc({.标识.}).remove({data{.元素.}}).then(. .).catch(..)</code></li>
<li>改<code>todos.doc({.标识.}).updata({data{.元素.}}).then(..).catch(..)</code></li>
<li>查<code>todos.doc({.标识.}).updata({data{.元素.}}).then(..).catch(..)</code></li>
</ul>
<h2 id="云函数"><a href="#云函数" class="headerlink" title="云函数"></a>云函数</h2><blockquote>
<p>类似Node.js 相当于后端</p>
</blockquote>
<h2 id="云储存"><a href="#云储存" class="headerlink" title="云储存"></a>云储存</h2><blockquote>
<p>存储文件，视频 音频等</p>
</blockquote>
<h2 id="Bug"><a href="#Bug" class="headerlink" title="Bug"></a>Bug</h2><p>小程序不支持 i++<br>在wxss中设置背景图片，图片的路径只能是https开头的网络图片</p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ul>
<li><p><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/" target="_blank" rel="noopener">小程序开发文档</a></p>
</li>
<li><p><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/" target="_blank" rel="noopener">慕课网小程序入门</a></p>
</li>
</ul>

        </div>

        <blockquote class="post-copyright">
    
    <footer>
        <a href="http://yoursite.com">
            <img src="https://yscoder.github.io/img/face.jpg" alt="张宁乐">
            张宁乐
        </a>
    </footer>
</blockquote>

        


        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/微信小程序/">微信小程序</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2019/08/16/小程序速查/&title=《小程序速记[基础]》 — Anson's Blog&pic=https://yscoder.github.io/img/face.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2019/08/16/小程序速查/&title=《小程序速记[基础]》 — Anson's Blog&source=张宁乐,博客" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2019/08/16/小程序速查/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《小程序速记[基础]》 — Anson's Blog&url=http://yoursite.com/2019/08/16/小程序速查/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2019/08/16/小程序速查/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2019/08/27/小程序之iPhone x适配/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">小程序之iPhone x适配</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2019/06/26/深浅拷贝/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">深浅拷贝</h4>
      </a>
    </div>
  
</nav>



    











    <!-- Valine Comments -->
    <div class="comments vcomment" id="comments"></div>
    <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
    <script src="//unpkg.com/valine@latest/dist/Valine.min.js"></script>
    <!-- Valine Comments script -->
    <script>
        var GUEST_INFO = ['nick','mail','link'];
        var guest_info = 'nick,mail'.split(',').filter(function(item){
          return GUEST_INFO.indexOf(item) > -1
        });
        new Valine({
            el: '#comments',
            notify: 'false' == 'true',
            verify: 'false' == 'true',
            appId: "gbSwUaucLkuxqOLxm131Mg9U-gzGzoHsz",
            appKey: "b9xU2qIPrm06S0uymbAfrGMD",
            avatar: "mm",
            placeholder: "要不要说点什么？",
            guest_info: guest_info.length == 0 ? GUEST_INFO : guest_info,
            pageSize: "10"
        })
    </script>
    <!-- Valine Comments end -->







</article>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>博客内容遵循 <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">知识共享 署名 - 非商业性 - 相同方式共享 4.0 国际协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p><span>张宁乐 &copy; 2017 - 2019</span>
            <span>
                
                Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
            </span>
			<span>
					Hosted by <a href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a>
			  </span>
        </p>
    </div>
</footer>
<!-- <script>
(function(){
    var bp = document.createElement("script");
    var curProtocol = window.location.protocol.split(":")[0];
    if (curProtocol === "https") {
        bp.src = "https://zz.bdstatic.com/linksubmit/push.js";
    }
    else {
        bp.src = "http://push.zhanzhang.baidu.com/push.js";
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script> -->

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://yoursite.com/2019/08/16/小程序速查/&title=《小程序速记[基础]》 — Anson's Blog&pic=https://yscoder.github.io/img/face.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://yoursite.com/2019/08/16/小程序速查/&title=《小程序速记[基础]》 — Anson's Blog&source=张宁乐,博客" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://yoursite.com/2019/08/16/小程序速查/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《小程序速记[基础]》 — Anson's Blog&url=http://yoursite.com/2019/08/16/小程序速查/&via=http://yoursite.com" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://yoursite.com/2019/08/16/小程序速查/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: false };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
